﻿using System;
using System.Text;
using System.Data;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

public partial class Admin_Admin_MainHtml : System.Web.UI.Page
{
    public string ShowRight;
    protected void Page_Load(object sender, EventArgs e)
    {

        //Response.Write(ApplicationInfo.ApplicationPath);
        //return;
        if (!AdminCheck.Check(this, 1))
        {

            Response.Redirect(AdminCheck.RedirectPage);
            return;
        }
        if (!Page.IsPostBack)
        {
            //  ShowRight = "asdasda";

            //  string rightid = new PublicSqlService().GetWords("Tbl_AdminLoginUser", "[Right]", "id=" + Request.QueryString["id"].ToString());
            //   DataTable dt = new UserService().GetUserRight(Session["uid"].ToString());
           string right="";
            DataTable dt = new UserService().GetUserRight(Session["uid"].ToString(),ref right);

            Session["Right"] = right;
            if (dt==null)
            {
            //   Tools.OpenWindow(this, "当前用户未设置权限，请使用管理员账户进行权限分配！", "Admin_Login.aspx");
               return;
            }
            ViewState["datatr"] = dt;

            DataView dv = dt.DefaultView;

            dv.RowFilter = "ParentID=0";
            dv.Sort = "SortID";
            StringBuilder sb = new StringBuilder();
            DataTable ntd = dv.ToTable();
            for (int i = 0; i < ntd.Rows.Count; i++)
            {
                DataView dv2 = ((DataTable)ViewState["datatr"]).DefaultView;

                dv2.RowFilter = "ParentID=" + ntd.Rows[i]["ID"].ToString();
                dv2.Sort = "SortID";
                sb.Append("case \"t" + ntd.Rows[i]["ID"].ToString() + "\":");
                sb.AppendLine();
                sb.Append(" htmlvalue = \"<ul>");
                for (int y = 0; y < dv2.Count; y++)
                {
                    sb.Append("<li><a  onclick=\\\"javascript:Url('" + dv2[y]["Url"].ToString() + "')\\\" >" + dv2[y]["RightName"].ToString() + "</a></li>");
                }

                sb.Append(" </ul>\"; ");
                sb.AppendLine();
                sb.Append(" break;");
            }
            ShowRight = sb.ToString();

        }
    }
}
